#include "idle.h"

namespace Core
{
    class IdlePrivate
    {
    public:
        IdlePrivate() {}
        ~IdlePrivate() {}
        std::function<void()> target;
    };

    Idle::~Idle()
    {
        O_PRIVATE_DELETE;
    }


    void Idle::SingleShot(int timeout, const std::function<void ()> &target)
    {
        QTimer::singleShot(timeout, new Idle(target), SLOT(invokeOnce()));
    }

    Idle::Idle(const std::function<void ()> &target)
        :O_PRIVATE_CREATE(Idle)
    {
        O_D(Idle);
        d->target = target;
    }

    void Idle::invokeOnce()
    {
        O_D(Idle);
        d->target();
        deleteLater();
    }
}
